import { http } from "@/utils/http";
import type { ResultTable, Result } from "@/api/type";

/** 模块名称 */
const modulePath = "/system";

/** 获取角色列表 */
export const getRoleList = (params?: object) => {
  return http.request<ResultTable>("get", modulePath + "/roles/list", {
    params
  });
};

/** 获取角色All列表 */
export const getAllRoleList = (params?: object) => {
  return http.request<Result<Array<any>>>("get", modulePath + "/roles/all", {
    params
  });
};

/** 添加角色 */
export const roleAdd = (data?: object) => {
  return http.request<Result<Object>>("post", modulePath + "/roles/add", {
    data
  });
};

/** 修改角色 */
export const roleUpdate = (data?: object) => {
  return http.request<Result<Object>>("put", modulePath + "/roles/update", {
    data
  });
};

/** 删除角色 */
export const roleDelete = (data?: object) => {
  return http.request<Result<Object>>("delete", modulePath + "/roles/delete", {
    data
  });
};

/** 获取角色详情 */
export const roleDetails = (data?: object) => {
  return http.request<Result<Object>>("get", modulePath + "/roles/details", {
    data
  });
};

/** 更新状态 */
export const updateStatus = (data?: object) => {
  return http.request<Result<Object>>(
    "put",
    modulePath + "/roles/updateStatus",
    {
      data
    }
  );
};

/** 更新MenuIds */
export const updateMenuIds = (data?: object) => {
  return http.request<Result<Object>>(
    "put",
    modulePath + "/roles/updateMenuIds",
    {
      data
    }
  );
};

/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<Result<Array<any>>>("get", modulePath + "/menus/all", {
    data
  });
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (params?: object) => {
  return http.request<Result<Array<any>>>(
    "get",
    modulePath + "/roles/getRoleMenuIds",
    {
      params
    }
  );
};

/** 获取部门列表 */
export const getDeptList = (params?: object) => {
  return http.request<ResultTable>("get", modulePath + "/depts/list", {
    params
  });
};

/** 获取部门列表 */
export const getDeptAllList = (params?: object) => {
  return http.request<Result<Array<any>>>("get", modulePath + "/depts/all", {
    params
  });
};

/** 添加部门 */
export const deptAdd = (data?: object) => {
  return http.request<Result<Object>>("post", modulePath + "/depts/add", {
    data
  });
};

/** 修改部门 */
export const deptUpdate = (data?: object) => {
  return http.request<Result<Object>>("put", modulePath + "/depts/update", {
    data
  });
};

/** 删除部门 */
export const deptDelete = (data?: object) => {
  return http.request<Result<Object>>("delete", modulePath + "/depts/delete", {
    data
  });
};

/** 添加用户角色 */
export const addRoleId = (data?: object) => {
  return http.request<Result<Object>>("put", modulePath + "/users/addRoleId", {
    data
  });
};

/** 获取用户角色列表 */
export const getRoleUserIds = (params?: object) => {
  return http.request<Result<Array<any>>>(
    "get",
    modulePath + "/users/getRoleUserIds",
    {
      params
    }
  );
};

/** 获取用户 */
export const getUserList = (params?: object) => {
  return http.request<ResultTable>("get", modulePath + "/users/getUserList", {
    params
  });
};

/** 添加用户 */
export const userAdd = (data?: object) => {
  return http.request<Result<Object>>("post", modulePath + "/users/add", {
    data
  });
};

/** 修改用户 */
export const userUpdate = (data?: object) => {
  return http.request<Result<Object>>("put", modulePath + "/users/update", {
    data
  });
};

/** 删除用户 */
export const userDelete = (data?: object) => {
  return http.request<Result<Object>>("delete", modulePath + "/users/delete", {
    data
  });
};

/** 用户详情 */
export const userDetails = (data?: object) => {
  return http.request<Result<Object>>("delete", modulePath + "/users/details", {
    data
  });
};

/** 更新密码 */
export const updatePassword = (data?: object) => {
  return http.request<Result<Object>>(
    "put",
    modulePath + "/users/updatePassword",
    {
      data
    }
  );
};
/** 上传用户头像 */
export const uploadAvatar = (data?: object) => {
  return http.post(
    modulePath + "/users/uploadAvatar",
    { data },
    {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }
  );
};
